﻿using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
//using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace classTest
{
    /// <summary>
    /// BufferLayerInfoWindow.xaml 的交互逻辑
    /// </summary>
    /// 
    public partial class BufferLayerInfoWindow : Window
    {

        private Geometry resultGeometry;
        private FeatureQueryResult pQueryResult;
        private MapView mapView;
        private BufferEffectLayerAttributeTableWindow belatw;
        public BufferLayerInfoWindow(Geometry resultGeometry1, FeatureQueryResult pQueryResult1, MapView mapView1)
        {
            InitializeComponent();
            resultGeometry = resultGeometry1;
            pQueryResult = pQueryResult1;
            mapView = mapView1;
            Initialize();
        }

        private void Initialize()
        {
            if (resultGeometry != null)
            {
                occupyArea.Text = $"{Math.Round(GeometryEngine.AreaGeodetic(resultGeometry), 3)}米²";
            }
            else
            {
                occupyArea.Text = "无";
            }
            if (pQueryResult!=null && pQueryResult.Count() > 0)
            {
                visitAttributeTable.IsEnabled = true;
                if (pQueryResult.First().Geometry.GeometryType == GeometryType.Polygon)
                {
                    double area = 0;
                foreach (Feature f in pQueryResult)
                {
                    area += GeometryEngine.AreaGeodetic(f.Geometry);
                }
                effectArea.Text = $"{Math.Round(area, 2)}米²";
                }
                else
                {
                    effectArea.Text = "仅支持统计面要素";
                }
            }
        }
        private void VisitAttributeTable_Click(object sender, RoutedEventArgs e)
        {
            belatw = new BufferEffectLayerAttributeTableWindow(pQueryResult,mapView);
            belatw.ShowDialog();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            if (belatw != null) belatw.Close();
        }
    }
}
